import { passwordLogin } from "@/api/login";
import { setToken } from "@/utils/auth";

export default {
  namespaced: true,
  state: {
    phone: "",
    password: "",
  },
  mutations: {
    // 修改
    toggleLogin: (state, payload) => {
      state.phone = payload.username;
      state.password = payload.password;
    },
  },
  actions: {
    // get: _.debounce(async ({ state,commit }) => {
    //     const { curPage, eachPage } = state;
    //     const data = await StudentsApi.get({ curPage, eachPage });
    //     commit("update",data);
    // },500)

    login: async ({ state }) => {
      const { phone, password } = state;
      const { success, resultObj } = await passwordLogin({ phone, password });
      setToken(resultObj.token);
      return success;
    },
  },
  getters: {},
};
